package ClassTest;
/*
空指针异常NullPointerException
关于垃圾回收器GC
再java语言中，垃圾回收器主要针对的时堆内存，当一个Java对象没有
任何引用指向该对象的时候，GC会考虑将该垃圾数据回收掉
 */
public class NullPointerTest {
    public static void main(String[] args){
        Customer c = new Customer();
        c.id = 12;
        System.out.println(c.id);

        // c = null;   将c赋予空值，会发生空指针异常 c中保存的Customer对象地址没了，对象将会等待垃圾回收机制回收，无法再利用
        // System.out.println(c.id);
        /*
        空指针异常
        Exception in thread "main" java.lang.NullPointerException: Cannot read field "id" because "c" is null
        at ClassTest.NullPointerTest.main(NullPointerTest.java:12)
         */


    }
}
class Customer{
    int id;

}
